import axios from 'axios'
import { Loading } from "element-ui";
import router from '../router'


const PRODUCT_URL = 'https://www.ccclkj.cn:2036/'
// const MOCK_URL = 'http://127.0.0.1:2036/'
const MOCK_URL = 'http://192.168.0.103:2036/'
// const MOCK_URL = 'https://www.ccclkj.cn:2030/'

export const baseurl = process.env.NODE_ENV === 'production' ? PRODUCT_URL : MOCK_URL;


export function request(config) {
    const instance = axios.create({
        baseURL: baseurl,
    });
    const loading = Loading.service({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.1)"
    });
    instance.interceptors.request.use(config => {
        return config
    }, err => {
        console.log(err)
    })
    instance.interceptors.response.use(res => {
        loading.close();
        // if (res.data != null) {
        //     if (res.data.msg == '没有token') {
        //         window.sessionStorage.setItem('timeout', 'true');
        //         router.replace("/login");
        //     }
        // }
        return res.data
    }, err => {
        console.log(err)
    })

    return instance(config)
}